/*****************************************************************************/
/**
 *  @file   MainView.h
 *  @author Naohisa Sakamoto
 */
/*----------------------------------------------------------------------------
 *
 *  Copyright (c) Visualization Laboratory, Kyoto University.
 *  All rights reserved.
 *  See http://www.viz.media.kyoto-u.ac.jp/kvs/copyright/ for details.
 *
 *  $Id: MainView.h 86 2013-12-24 04:06:33Z naohisa.sakamoto $
 */
/*****************************************************************************/
#pragma once
#include <kvs/Vector4>
#include <kvs/Matrix44>
#include <kvs/glut/Screen>
#include <kvs/glut/Timer>

namespace kvs { class StochasticRenderingCompositor; }
namespace kvs { namespace glut { class Application; } }
class OverView;
class DataSet;
class ResourceMonitor;
class ResourceLabelWidget;
class OverViewUpdator;

class MainView : public kvs::glut::Screen
{
private:

    OverView* m_over_view; ///< pointer to the over view
    DataSet* m_data_set; ///< pointer to the data set
    ResourceMonitor* m_resource_monitor; ///< pointer to the resource monitor

    ResourceLabelWidget* m_resource_label_widget; ///< pointer to the resource label widget
    OverViewUpdator* m_over_view_updator; ///< pointer to the over view updator
    kvs::StochasticRenderingCompositor* m_compositor; ///< pointer to the compositor

    kvs::Mat4 m_initial_modelview; ///< intial modelview matrix
    kvs::Mat4 m_initial_projection; ///< intial projection matrix
    kvs::Vec4 m_initial_viewport; ///< intial viewport vector

    size_t m_stored_particle_data_size; ///< stored particle data size on GPU
    size_t m_stored_volume_data_size; ///< stored volume data size on GPU

    kvs::glut::Timer m_timer;

public:

    MainView( kvs::glut::Application* app );
    ~MainView();

    void attachOverViewScreen( OverView* over_view );
    void attachDataSet( DataSet* data_set );
    void attachResourceMonitor( ResourceMonitor* resource_monitor );
    void loadObject();

    void incrementTimeStep( const bool loop = false );
    void decrementTimeStep( const bool loop = false );
    void startTimer();
    void stopTimer();
    void toggleTimer();
    bool isTimerStopped() const;

    void adaptiveSwitching();

    void changeRenderer();
    void cullVolume();

private:

    bool has_OPBR();
    bool has_IPBR();
    bool can_OPBR();
    bool can_IPBR();
    void switch_to_OPBR();
    void switch_to_IPBR();
};
